<?php
class ProductController {
	public function lists (){
		$data =  HttpServerManager::getProductServer()->pagingBySearch($_GET);
		$type = Common::_t('product_type');
		$status = Common::_t('product_status');
		$activeType = Common::_t('active_type');
		
		foreach ($data['list'] as $k=>$v){
			$data['list'][$k]['type'] = $type[$data['list'][$k]['type']];
			$data['list'][$k]['status'] = $status[$data['list'][$k]['status']];
			$data['list'][$k]['activeType_name'] = $activeType[$data['list'][$k]['active_type']];
		}
		
		$data['type_options'] = $type;
		$data['status_options'] = $status;
		$data['activeType_options'] = $activeType;
		
		return $data;
	}
	public function add(){
		$data = array();
		if (!empty($_GET['id'])){
			$data = HttpDaoManager::getProductDao()->get($_GET['id']);
		}else{
			$sysKey = 'PRODUCT_NO';
			$key_info  =  HttpDaoManager::getSysConfigDao()->getBySyskey($sysKey);
			$seed_no = $key_info['sys_value'];	
			$data['serial_number'] = Common::executeSerialNumber('P','7',$seed_no);
			$sys_update = array();
			$sys_update['sys_value']=$seed_no+1;
			$sys_id = $key_info['id'];
			$key_info  =  HttpDaoManager::getSysConfigDao()->update($sys_update,$sys_id);				
		}
		$prodcut_type_id_list = array(PRODUCT_TYPE_3);
		$product_return_ticket = HttpDaoManager::getProductDao()->getDataPairListByType($prodcut_type_id_list);
		$return_ticket = array();
		foreach ($product_return_ticket  as $v){
			$return_ticket[$v['id']] = $v['name'];
		}
		
		$type = Common::_t('product_type');
		$typeOptions = page_modifier_options($type,getStr($data,'type'));
		$status  = Common::_t('product_status');
		$statusOptions = page_modifier_options($status,getStr($data,'status'));
		$returnTicketOptions =  page_modifier_options_ext($return_ticket,getStr($data,'return_ticket'));
		
		$activeType = Common::_t('active_type');
		$activeTypeOptions = page_modifier_options($activeType,getStr($data,'active_type'));
		
		$targetCourse = Common::_t('target_course');
		$targetCourseOptions = page_modifier_options($targetCourse,getStr($data,'target_course'));
		
		$data['typeOptions'] = $typeOptions;
		$data['statusOptions'] = $statusOptions;
		$data['activeTypeOptions'] = $activeTypeOptions;
		$data['targetCourseOptions'] = $targetCourseOptions;
		$returnTicketOptions =  page_modifier_options_ext($return_ticket,getStr($data,'return_ticket'));
		$data['returnTicketOptions'] = $returnTicketOptions;
		$product_unit  = Common::_t('product_unit');
		$productUnitOptions =  page_modifier_options_ext($product_unit,getStr($data,'unit'));
		$data['productUnitOptions'] = $productUnitOptions;
		return $data;
	}
	public function subAdd(){
		HttpServerManager::getProductServer()->add($_POST);
		ClassManager::getToos()->msgbox(Common::_t('data_insert_success'));
	}
	public function subUpdate(){
		HttpDaoManager::getProductDao()->update($_POST, $_POST['id']);
		ClassManager::getToos()->msgbox(Common::_t('data_edit_success'),'product_lists.html');
	}
	public function delete(){
		
		HttpServerManager::getProductServer()->deleteBatchByid($_GET['id']);
		ClassManager::getToos()->msgbox(Common::_t('data_del_success'));

	}
}
?>